package com.losdun.aftersales.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.losdun.aftersales.liteweb.vo.TaskVo;
import com.losdun.common.annotation.Excel;
import com.losdun.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;

/**
 * 合同订单对象 aftersales_contract_order
 * 
 * @author swordye
 * @date 2025-08-19
 */
public class ContractOrder extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** ID */
    private Long id;

    /** 订单编号 */
    @Excel(name = "订单编号")
    private String orderNo;

    /**  */
    private String openId;

    /** 用户姓名 */
    @Excel(name = "用户姓名")
    private String userName;

    /** 手机号 */
    @Excel(name = "手机号")
    private String mobile;

    /** 产品型号 */
    @Excel(name = "产品型号")
    private String productModel;

    /** 用户地址 */
    @Excel(name = "用户地址")
    private String address;

    /** 购买时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "购买时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date purchaseTime;

    /** 订单状态 */
    @Excel(name = "订单状态")
    private Integer status;

    /** 是否评论 */
    @Excel(name = "是否评论")
    private Integer commentStatus;

    /** 物流单号 */
    @Excel(name = "物流单号")
    private String expressNo;

    /** 交付期限 */
    @Excel(name = "交付期限")
    private Integer deliveryDays;

    /** 维保结束日期 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "维保结束日期", width = 30, dateFormat = "yyyy-MM-dd")
    private Date serviceEndDate;

    @TableField(exist = false)
    private Integer serviceOver;

    /** 业务员ID */
    private Long salesmanId;

    /** 业务员 */
    @Excel(name = "业务员")
    private String salesman;

    /** 1：包含测量；0：不包含测量 */
    @Excel(name = "1：包含测量；0：不包含测量")
    private Integer measureFlag;

    /** 1:包含安装；0：不包含安装 */
    @Excel(name = "1:包含安装；0：不包含安装")
    private Integer installFlag;

    /** 1:包含物流；0：不包物流 */
    @Excel(name = "1:包含物流；0：不包物流")
    private Integer expressFlag;

    /** 订单部 */
    @Excel(name = "订单部")
    private Long marketDept;

    /** 工程部 */
    @Excel(name = "工程部")
    private Long projectDept;

    /** 制作工厂 */
    @Excel(name = "制作工厂")
    private String factory;

    /** 1:允许二次预约；0：不允许二次预约 */
    @Excel(name = "1:允许二次预约；0：不允许二次预约")
    private Integer secondTimes;

    /** 交期开始时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "交期开始时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date deliveryStartTime;

    /** 设计确认时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate designDate;
    /** 制作完成时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate factoryDate;
    /** 发货时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate shippingDate;
    /** 收货时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate receivedDate;

    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate completeDate;

    /** 备注 */
    @Excel(name = "备注")
    private String remarks;

    private boolean isMember;

    private List<TaskVo> stepList;

    private String attachUrl;
    private String imagesUrl;
    private Integer partsMonths;
    private Integer elecMonths;
    private Integer doorYears;
    private String repairRange;

    /**
     * 是否发送过消息
     */
    private Integer msgSend;

    public Integer getMsgSend() {
        return msgSend;
    }

    public void setMsgSend(Integer msgSend) {
        this.msgSend = msgSend;
    }

    public LocalDate getElecEndDate() {
        if(elecMonths != null && completeDate!=null){
            return completeDate.plusMonths(elecMonths);
        }
        return null;
    }

    public LocalDate getPartsEndDate() {
        if(partsMonths != null && completeDate!=null){
            return completeDate.plusMonths(partsMonths);
        }
        return null;
    }

    public LocalDate getDoorEndDate() {
        if(doorYears != null && completeDate!=null){
            return completeDate.plusYears(doorYears);
        }
        return null;
    }

    public String getImagesUrl() {
        return imagesUrl;
    }

    public void setImagesUrl(String imagesUrl) {
        this.imagesUrl = imagesUrl;
    }

    public Integer getPartsMonths() {
        return partsMonths;
    }

    public void setPartsMonths(Integer partsMonths) {
        this.partsMonths = partsMonths;
    }

    public Integer getElecMonths() {
        return elecMonths;
    }

    public void setElecMonths(Integer elecMonths) {
        this.elecMonths = elecMonths;
    }

    public Integer getDoorYears() {
        return doorYears;
    }

    public void setDoorYears(Integer doorYears) {
        this.doorYears = doorYears;
    }

    public String getRepairRange() {
        return repairRange;
    }

    public void setRepairRange(String repairRange) {
        this.repairRange = repairRange;
    }

    public String getAttachUrl() {
        return attachUrl;
    }

    public void setAttachUrl(String attachUrl) {
        this.attachUrl = attachUrl;
    }
    public LocalDate getCompleteDate() {
        return completeDate;
    }

    public void setCompleteDate(LocalDate completeDate) {
        this.completeDate = completeDate;
    }

    public LocalDate getDesignDate() {
        return designDate;
    }

    public void setDesignDate(LocalDate designDate) {
        this.designDate = designDate;
    }

    public LocalDate getFactoryDate() {
        return factoryDate;
    }

    public void setFactoryDate(LocalDate factoryDate) {
        this.factoryDate = factoryDate;
    }

    public LocalDate getShippingDate() {
        return shippingDate;
    }

    public void setShippingDate(LocalDate shippingDate) {
        this.shippingDate = shippingDate;
    }

    public LocalDate getReceivedDate() {
        return receivedDate;
    }

    public void setReceivedDate(LocalDate receivedDate) {
        this.receivedDate = receivedDate;
    }

    public boolean isMember() {
        return isMember;
    }
    public void setMember(boolean member) {
        isMember = member;
    }
    public List<TaskVo> getStepList() {
        return stepList;
    }

    public void setStepList(List<TaskVo> stepList) {
        this.stepList = stepList;
    }

    public Integer getServiceOver() {
        if(serviceEndDate==null){
            serviceOver = 0;

        }else if (serviceEndDate.getTime() > System.currentTimeMillis() + 24 * 60 * 60 * 1000) {
            serviceOver = 0;
        } else {
            serviceOver = 1;
        }
        return serviceOver;
    }

    public void setServiceOver(Integer serviceOver) {
        this.serviceOver = serviceOver;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

    public Long getId() 
    {
        return id;
    }
    public void setOrderNo(String orderNo) 
    {
        this.orderNo = orderNo;
    }

    public String getOrderNo() 
    {
        return orderNo;
    }
    public void setOpenId(String openId) 
    {
        this.openId = openId;
    }

    public String getOpenId() 
    {
        return openId;
    }
    public void setUserName(String userName) 
    {
        this.userName = userName;
    }

    public String getUserName() 
    {
        return userName;
    }
    public void setMobile(String mobile) 
    {
        this.mobile = mobile;
    }

    public String getMobile() 
    {
        return mobile;
    }
    public void setProductModel(String productModel) 
    {
        this.productModel = productModel;
    }

    public String getProductModel() 
    {
        return productModel;
    }
    public void setAddress(String address) 
    {
        this.address = address;
    }

    public String getAddress() 
    {
        return address;
    }
    public void setPurchaseTime(Date purchaseTime) 
    {
        this.purchaseTime = purchaseTime;
    }

    public Date getPurchaseTime() 
    {
        return purchaseTime;
    }
    public void setStatus(Integer status) 
    {
        this.status = status;
    }

    public Integer getStatus() 
    {
        return status;
    }
    public void setCommentStatus(Integer commentStatus) 
    {
        this.commentStatus = commentStatus;
    }

    public Integer getCommentStatus() 
    {
        return commentStatus;
    }
    public void setExpressNo(String expressNo) 
    {
        this.expressNo = expressNo;
    }

    public String getExpressNo() 
    {
        return expressNo;
    }
    public void setDeliveryDays(Integer deliveryDays) 
    {
        this.deliveryDays = deliveryDays;
    }

    public Integer getDeliveryDays() 
    {
        return deliveryDays;
    }
    public void setServiceEndDate(Date serviceEndDate) 
    {
        this.serviceEndDate = serviceEndDate;
    }

    public Date getServiceEndDate() 
    {
        return serviceEndDate;
    }
    public void setSalesmanId(Long salesmanId) 
    {
        this.salesmanId = salesmanId;
    }

    public Long getSalesmanId() 
    {
        return salesmanId;
    }
    public void setSalesman(String salesman) 
    {
        this.salesman = salesman;
    }

    public String getSalesman() 
    {
        return salesman;
    }
    public void setMeasureFlag(Integer measureFlag) 
    {
        this.measureFlag = measureFlag;
    }

    public Integer getMeasureFlag() 
    {
        return measureFlag;
    }
    public void setInstallFlag(Integer installFlag) 
    {
        this.installFlag = installFlag;
    }

    public Integer getInstallFlag() 
    {
        return installFlag;
    }
    public void setExpressFlag(Integer expressFlag) 
    {
        this.expressFlag = expressFlag;
    }

    public Integer getExpressFlag() 
    {
        return expressFlag;
    }
    public void setMarketDept(Long marketDept) 
    {
        this.marketDept = marketDept;
    }

    public Long getMarketDept() 
    {
        return marketDept;
    }
    public void setProjectDept(Long projectDept) 
    {
        this.projectDept = projectDept;
    }

    public Long getProjectDept() 
    {
        return projectDept;
    }
    public void setFactory(String factory) 
    {
        this.factory = factory;
    }

    public String getFactory() 
    {
        return factory;
    }
    public void setSecondTimes(Integer secondTimes) 
    {
        this.secondTimes = secondTimes;
    }

    public Integer getSecondTimes() 
    {
        return secondTimes;
    }
    public void setDeliveryStartTime(Date deliveryStartTime) 
    {
        this.deliveryStartTime = deliveryStartTime;
    }

    public Date getDeliveryStartTime() 
    {
        return deliveryStartTime;
    }
    public void setRemarks(String remarks) 
    {
        this.remarks = remarks;
    }

    public String getRemarks() 
    {
        return remarks;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("id", getId())
            .append("orderNo", getOrderNo())
            .append("openId", getOpenId())
            .append("userName", getUserName())
            .append("mobile", getMobile())
            .append("productModel", getProductModel())
            .append("address", getAddress())
            .append("purchaseTime", getPurchaseTime())
            .append("status", getStatus())
            .append("commentStatus", getCommentStatus())
            .append("expressNo", getExpressNo())
            .append("deliveryDays", getDeliveryDays())
            .append("serviceEndDate", getServiceEndDate())
            .append("salesmanId", getSalesmanId())
            .append("salesman", getSalesman())
            .append("measureFlag", getMeasureFlag())
            .append("installFlag", getInstallFlag())
            .append("expressFlag", getExpressFlag())
            .append("marketDept", getMarketDept())
            .append("projectDept", getProjectDept())
            .append("factory", getFactory())
            .append("secondTimes", getSecondTimes())
            .append("deliveryStartTime", getDeliveryStartTime())
            .append("remarks", getRemarks())
            .append("createTime", getCreateTime())
            .append("updateTime", getUpdateTime())
            .toString();
    }
}
